#include "user.hxx"
#include "user-odb.hxx"
#include "chat_session_member.hxx"
#include "chat_session_member-odb.hxx"
#include "mysql_chat_session_member.hpp"
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式， false-调试； true-发布");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");


void signal_append(ChatSystem::ChatSessionMemberTable& csm_table)
{
    ChatSystem::ChatSessionMember session1("session1", "uid1");
    ChatSystem::ChatSessionMember session2("session2", "uid2");
    csm_table.append(session1);
    csm_table.append(session2);
}


void multi_append(ChatSystem::ChatSessionMemberTable& csm_table)
{
    std::vector<ChatSystem::ChatSessionMember> csm_lists;
    csm_lists.push_back({"session1", "uid2"});
    csm_lists.push_back({"session1", "uid3"});
    csm_lists.push_back({"session1", "uid4"});
    csm_lists.push_back({"session1", "uid5"});

    csm_lists.push_back({"session2", "uid5"});
    csm_lists.push_back({"session2", "uid6"});
    csm_lists.push_back({"session2", "uid7"});

    csm_lists.push_back({"session3", "uid3"});
    csm_lists.push_back({"session4", "uid4"});
    csm_table.append(csm_lists);
}

void signal_remove (ChatSystem::ChatSessionMemberTable& csm_table)
{
    ChatSystem::ChatSessionMember session1("session1", "uid1");
    csm_table.remove(session1);
}

void all_remove (ChatSystem::ChatSessionMemberTable& csm_table)
{
    csm_table.remove("session1");
}

void get_members (ChatSystem::ChatSessionMemberTable& csm_table)
{
    std::vector<std::string> res = csm_table.members("session2");
    for(auto& uid : res)
    {
        std::cout << uid << std::endl;
    }
}

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    ChatSystem::InitLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto db = ChatSystem::ODBFactory::create("root", "zhi204071", "127.0.0.1", "chatsystem", "utf8", 0, 1);
    ChatSystem::ChatSessionMemberTable csm_table(db);

    // signal_append(csm_table);

    // multi_append(csm_table);

    // signal_remove(csm_table);

    // all_remove(csm_table);

    // get_members(csm_table);
    return 0;
}